package com.jindy.module.returnreceiptorder.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.machine.domain.MachineRecord;
import com.jindy.module.order.domain.Order;
import com.jindy.module.returnreceiptorder.domain.ReturnReceiptOrder;
import com.jindy.module.returnreceiptorder.service.IReturnReceiptOrderService;
import com.jindy.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 回货入库单Controller
 *
 * @author ruoyi
 * @date 2022-10-19
 */
@RestController
@RequestMapping("/module/returnReceiptOrder")
public class ReturnReceiptOrderController extends BaseController
{
    @Autowired
    private IReturnReceiptOrderService returnReceiptOrderService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询回货入库单列表
     */
    @PreAuthorize("@ss.hasPermi('module:returnReceiptOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReturnReceiptOrder returnReceiptOrder)
    {
        //添加权限
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        returnReceiptOrder.setUserId(sysUser.getUserId());
        startPage();
        List<ReturnReceiptOrder> list = returnReceiptOrderService.selectReturnReceiptOrderList(returnReceiptOrder);
        return getDataTable(list);
    }

    /**
     * 导出回货入库单列表
     */
    @PreAuthorize("@ss.hasPermi('module:returnReceiptOrder:export')")
    @Log(title = "回货入库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReturnReceiptOrder returnReceiptOrder)
    {
        //添加权限
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        returnReceiptOrder.setUserId(sysUser.getUserId());

        List<ReturnReceiptOrder> list = returnReceiptOrderService.selectReturnReceiptOrderList(returnReceiptOrder);
        ExcelUtil<ReturnReceiptOrder> util = new ExcelUtil<ReturnReceiptOrder>(ReturnReceiptOrder.class);
        util.exportExcel(response, list, "回货入库单数据");
    }

    /**
     * 获取回货入库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:returnReceiptOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(returnReceiptOrderService.selectReturnReceiptOrderById(id));
    }

    /**
     * 新增回货入库单
     */
    @PreAuthorize("@ss.hasPermi('module:returnReceiptOrder:add')")
    @Log(title = "回货入库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReturnReceiptOrder returnReceiptOrder)
    {
        return toAjax(returnReceiptOrderService.insertReturnReceiptOrder(returnReceiptOrder));
    }

    /**
     * 扫码新增机器回货记录
     */
    @Log(title = "回货入库单", businessType = BusinessType.INSERT)
    @PostMapping("/add2")
    public AjaxResult add2(@RequestBody  MachineRecord machineRecord)
    {
        return toAjax(returnReceiptOrderService.insertReturnReceiptOrder2(machineRecord));
    }


    /**
     * 扫码查询机器所属未完成订单
     */
    @GetMapping("/machineOrder")
    public AjaxResult machineOrder(MachineRecord machineRecord)
    {
        return AjaxResult.success(returnReceiptOrderService.selectOrderByMachineNo(machineRecord));
    }

    /**
     * 修改回货入库单
     */
    @PreAuthorize("@ss.hasPermi('module:returnReceiptOrder:edit')")
    @Log(title = "回货入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReturnReceiptOrder returnReceiptOrder)
    {
        return toAjax(returnReceiptOrderService.updateReturnReceiptOrder(returnReceiptOrder));
    }

    /**
     * 删除回货入库单
     */
    @PreAuthorize("@ss.hasPermi('module:returnReceiptOrder:remove')")
    @Log(title = "回货入库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(returnReceiptOrderService.deleteReturnReceiptOrderByIds(ids));
    }
}
